//
//  HSYBaseRefleshViewController.m
//  高仿暴走斗图
//
//  Created by key on 16/3/15.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "HSYBaseRefleshViewController.h"
#import "SVPullToRefresh.h"

static double kDelayInSeconds = 0.5f;

@interface HSYBaseRefleshViewController ()

@end
@implementation HSYBaseRefleshViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
}



#pragma mark - Pull Down 

- (void)addPullDownToScrollView:(UIScrollView *)scrollView withActionHandler:(void (^)(void))actionHandler {
    //添加下拉刷新
    [scrollView addPullToRefreshWithActionHandler:actionHandler];
}

- (void)startPullDownAnimationToScrollView:(UIScrollView *)scrollView {
    
    NSParameterAssert(scrollView.pullToRefreshView);
    //开始下拉刷新的动画
    [scrollView.pullToRefreshView startAnimating];
//    if (scrollView.infiniteScrollingView) {
//        [self stopPullUpAnimationToScrollView:scrollView];
//    }
}

- (void)stopPullDownAnimationToBlock:(dispatch_block_t)block {
    
    //延迟动画
    double delayInSeconds = kDelayInSeconds;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    //停止下拉刷新的动画
    dispatch_after(popTime, dispatch_get_main_queue(), block);
    
//    [NSObjcGCD gcd_DelayExecutionForDelayInSeconds:kDelayInSeconds dispatchCompletion:block];
}

- (void)stopPullDownAnimationToScrollView:(UIScrollView *)scrollView {
    //停止下拉
    NSParameterAssert(scrollView.pullToRefreshView);
    [scrollView.pullToRefreshView stopAnimating];
}

#pragma mark - Pull Up

- (void)addPullUpToScrollView:(UIScrollView *)scrollView withActionHandler:(void (^)(void))actionHandler {
    //添加上拉刷新
    [scrollView addInfiniteScrollingWithActionHandler:actionHandler];
}


- (void)startPullUpAnimationToScrollView:(UIScrollView *)scrollView {
    
    NSParameterAssert(scrollView.infiniteScrollingView);
    //开始上拉刷新动画
    [scrollView.infiniteScrollingView startAnimating];
}


- (void)stopPullUpAnimationToBlock:(dispatch_block_t)block {
    
    //延迟动画
    double delayInSeconds = kDelayInSeconds;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    //停止上拉刷新的动画
    dispatch_after(popTime, dispatch_get_main_queue(), block);
    
//    [NSObjcGCD gcd_DelayExecutionForDelayInSeconds:kDelayInSeconds dispatchCompletion:block];
}

- (void)stopPullUpAnimationToScrollView:(UIScrollView *)scrollView {
    //停止上拉
    NSParameterAssert(scrollView.infiniteScrollingView);
    [scrollView.infiniteScrollingView stopAnimating];
}

@end
